package com.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dao.LoginDao;
import com.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author WZ
 * @version 1.0
 * @date 2021/8/23 10:10
 */
@Service
public class LoginService {
@Resource
    private LoginDao loginDao;
@Autowired
private TalkKiaraService talkKiaraService;
//查询数据库验证密码是否正确

    public List<Login> login(String account){

        List<Login> password2=loginDao.login(account);

        return password2;

    }
//返回用户信息
    public List<User> finduserlist(String account){
      return   loginDao.findUser(account);
    }

    public List<UserRole> findroles(String userId){
        return  loginDao.findRole(userId);
    }
public List<UserRole> allRole(){
        return loginDao.AllRole();
}

public int addUser(TalkUser talkUser){

    int insert = loginDao.addUser(talkUser);
    TalkKiara byId = talkKiaraService.getById(talkUser.getKiaraId());
    byId.setUsed(1);
    talkKiaraService.update(byId,new LambdaQueryWrapper<TalkKiara>().eq(TalkKiara::getId,byId.getId()));
    return insert;
}

}
